package com.cdream.basic.algorithm.leetcode.findElement;

import java.util.Arrays;

/**
 * @author cdream
 * @date 7/2/21
 */
public class Question1833 {
    public int maxIceCream(int[] costs, int coins) {
        Arrays.sort(costs);
        int i = 0,index=0;;
        while(index<costs.length){
            if(coins>=costs[index]){
                coins-=costs[index];
                i++;
                index++;
            }else{
                break;
            }
        }
        return i;
    }

    public static void main(String[] args) {
        new Question1833().maxIceCream(new int[]{1,3,2,4,1},7);
    }
}
